package comment_api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"giv-vue-blog/global"
	"giv-vue-blog/models"
	"giv-vue-blog/models/res"
	"giv-vue-blog/service/redis_ser"
)

type CommentIDRequest struct {
	ID uint `json:"id" form:"id" uri:"id"`
}

// CommentDigg 评论点赞
// @Tags 评论管理
// @Summary 评论点赞
// @Description 评论点赞
// @Param id path int  true "id"
// @Router /api/comments/{id} [get]
// @Produce json
// @Success 200 {object} res.Response{}
func (CommentApi) CommentDigg(c *gin.Context) {
	var CommentID CommentIDRequest
	err := c.ShouldBindUri(&CommentID)
	if err != nil {
		res.FailedWithCode(res.ArgumentError, c)
		return
	}
	var commentModel models.CommentModel
	err = global.DB.Take(&commentModel, CommentID.ID).Error
	if err != nil {
		res.FailedWithMsg("评论不存在", c)
		return
	}
	//评论点赞
	redis_ser.NewCommentDigg().Set(fmt.Sprintf("%d", CommentID.ID))
	res.OkWithMsg("点赞成功", c)
}
